/*
 * Powered By [cciot base platform]
 * Web Site: http://www.cciot.net
 * Since 2012 - 2013
 */

package net.cciot.platform.core.service;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import java.io.*;
import java.net.*;
import java.util.*;

import java.math.BigDecimal;
import java.math.BigInteger;

import net.cciot.platform.common.base.*;

import static net.cciot.platform.common.util.DateFormats.*;
import static net.cciot.platform.common.util.GlobalMessages.*;
import static net.cciot.platform.common.util.SpringMVCUtils.toModelMap;
import static net.cciot.platform.common.util.MybatisPageQueryUtils.pageQuery;

import static cn.org.rapid_framework.util.ValidationErrorsUtils.convert;
import static cn.org.rapid_framework.beanutils.BeanUtils.copyProperties;
import static cn.org.rapid_framework.util.holder.BeanValidatorHolder.validateWithException;
import cn.org.rapid_framework.util.DateConvertUtils;

import cn.org.rapid_framework.page.PageRequest;
import cn.org.rapid_framework.page.Page;

import net.cciot.platform.core.model.*;
import net.cciot.platform.core.dao.*;
import net.cciot.platform.core.service.*;
import net.cciot.platform.core.query.*;


/**
 * @author anduo email:anduo1989@gmail.com
 * @version 1.0
 * @since 1.0
 */
@Service
@Transactional
public class BaseUsersManager {

	private BaseUsersDao baseUsersDao;
	/**增加setXXXX()方法,spring就可以通过autowire自动设置对象属性,请注意大小写*/
	public void setBaseUsersDao(BaseUsersDao dao) {
		this.baseUsersDao = dao;
	}
	
	/** 
	 * 创建BaseUsers
	 **/
	public BaseUsers save(BaseUsers baseUsers) {
	    Assert.notNull(baseUsers,"'baseUsers' must be not null");
	    initDefaultValuesForCreate(baseUsers);
	    new BaseUsersChecker().checkCreateBaseUsers(baseUsers);
	    this.baseUsersDao.save(baseUsers);
	    return baseUsers;
	}
	
	/** 
	 * 更新BaseUsers
	 **/	
    public BaseUsers update(BaseUsers baseUsers) {
        Assert.notNull(baseUsers,"'baseUsers' must be not null");
        new BaseUsersChecker().checkUpdateBaseUsers(baseUsers);
        this.baseUsersDao.update(baseUsers);
        return baseUsers;
    }	
    
	/** 
	 * 删除BaseUsers
	 **/
    public void removeById(java.lang.String id) {
        this.baseUsersDao.deleteById(id);
    }
    
	/** 
	 * 根据ID得到BaseUsers
	 **/    
    public BaseUsers getById(java.lang.String id) {
        return this.baseUsersDao.getById(id);
    }
    
	/** 
	 * 分页查询: BaseUsers
	 **/      
	@Transactional(readOnly=true)
	public Page findPage(BaseUsersQuery query) {
	    Assert.notNull(query,"'query' must be not null");
		return baseUsersDao.findPage(query);
	}
	
    
	/**
	 * 为创建时初始化相关默认值 
	 **/
    public void initDefaultValuesForCreate(BaseUsers v) {
    }
    
    /**
     * BaseUsers的属性检查类,根据自己需要编写自定义检查
     **/
    public class BaseUsersChecker {
        /**可以在此检查只有更新才需要的特殊检查 */
        public void checkUpdateBaseUsers(BaseUsers v) {
            checkBaseUsers(v);
        }
    
        /**可以在此检查只有创建才需要的特殊检查 */
        public void checkCreateBaseUsers(BaseUsers v) {
            checkBaseUsers(v);
        }
        
        /** 检查到有错误请直接抛异常，不要使用 return errorCode的方式 */
        public void checkBaseUsers(BaseUsers v) {
        	// Bean Validator检查,属性检查失败将抛异常
            validateWithException(v);
            
        	//复杂的属性的检查一般需要分开写几个方法，如 checkProperty1(v),checkProperty2(v)
        }
    }
}
